package example;


import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

public class App {
    public static void main(String[] args) {
        try {
            //动态获取类
            Class clazz = Class.forName("example.Son");

            //注解扫描 判断类是否存在某个注解
            if (clazz.isAnnotationPresent(Description.class)) {
                Description desc = (Description) clazz.getAnnotation(Description.class);
                System.out.println(desc.version());
                System.out.println(desc.author());
                System.out.println(desc.desc());
            }

            Method[] methods = clazz.getMethods();
            //扫描方法上的注解信息
            for (Method method : methods) {
                if (method.isAnnotationPresent(Description.class)) {
                    Description desc = (Description) method.getAnnotation(Description.class);
                    System.out.println(desc.version());
                    System.out.println(desc.author());
                    System.out.println(desc.desc());
                }
            }

            //扫描方法上的注解信息2
            for (Method method : methods) {
                Annotation[] annotations = method.getAnnotations();
                for (Annotation annotation : annotations) {
                    if (annotation instanceof Description) {
                        Description desc = (Description) annotation;
                        System.out.println(desc.version());
                        System.out.println(desc.author());
                        System.out.println(desc.desc());
                    }
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }


}





